package com.supor.aiot.common.push;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.android.baseconfig.base.BaseActivity;
import com.android.baseconfig.base.BasePresenter;
import com.android.baseconfig.common.helper.ActivityManager;
import com.android.baseconfig.common.utils.Logc;
import com.supor.aiot.common.R;
import com.supor.aiot.common.app.SuporPresenter;

import androidx.annotation.Nullable;

public class NotificationActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification);
        findViewById(R.id.demo).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SuporPresenter.getInstance().startMain(NotificationActivity.this);
            }
        });
        handleIntent(getIntent());
        setIntent(null);
    }

    @Override
    protected int resourceId() {
        return 0;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleIntent(intent);
        setIntent(null);
    }

    private void handleIntent(Intent intent) {
        if (intent == null) {
            return ;
        }
        Activity activity = ActivityManager.getActivity(0);
        Logc.i("bottom activity: " + (activity == null ? "null" : activity.getClass().getName()));
        if (activity != null && !("MainActivity".equalsIgnoreCase(activity.getClass().getSimpleName()))) {
            SuporPresenter.getInstance().startMain(this);
            // ARouter.getInstance().build(PathUrl.PATH_MAIN).navigation();
        }
        finish();
        // Uri uri = intent.getData();
        // if (uri == null) {
        //     return ;
        // }
        // Logc.i(TAG, "handleIntent uri: " + uri.toString());
        // String params = intent.getStringExtra("data");
        // Logc.i(TAG, "handleIntent params: " + params);
        // Intent targetIntent = new Intent(NotificationActivity.this, NotificationActivity.class);
        // targetIntent.putExtra("uri", uri.toString());
        // targetIntent.putExtra("data", params);
        // startActivity(targetIntent);
    }
}
